<?php
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "EN") {
			$value = "../value/value_en.php";
		} else if($lang == "VN") {
			$value = "../value/value_vn.php";
		}
		else {
			$value = "../value/value_kr.php";
		}
		return $value;
	}
include '../connection/connection.php';	
$value = getlang();
$list=$_SESSION['sort'];
include($value);
	$page=$_GET['pages'];
	$str=$_GET['str'];
	$_SESSION['sortn']=$str;
	$flagDesc=$_GET['flagDesc'];
	
	$search=$_REQUEST['search'];
	$from=$_REQUEST['from'];
	$to=$_REQUEST['to'];
	$lstatus=$_REQUEST['status'];
	$oneday=$_REQUEST['oneday'];
	$twodays=$_REQUEST['twodays'];
	$oneweek=$_REQUEST['oneweek'];
	$onemonth=$_REQUEST['onemonth'];
	
	$rows_per_page = 20 ;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	if($flagDesc==1){

		if($list[$str]=="DESC")
			$list[$str]="ASC";
		else
			$list[$str]="DESC";
	}
	
	$emails = $_REQUEST['emails'];
	
	$sql = "SELECT lv.*,ui.email FROM `user_info` ui, log_viewer lv 
		WHERE lv.id = ui.id AND lv.`status` = 'logout' AND ui.email='".$emails."' ";
	$selectlogviewer = mysql_query($sql." ORDER BY ".$str." ".$list[$str]);
	$number_of_page = ceil ( mysql_num_rows( $selectlogviewer ) / $rows_per_page ); 
	

	$_SESSION['sort']=$list;
	?>
	<thead>
				<tr>
					<td align="center" style="width: 4%;color: #696969;"><?php echo $no?></td>
					<td align="center"><a onclick="sortandpagingViewerAll_LoginInDay('<?=$page?>','ui.email',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $useriforid ?></a></td>
					<td align="center"><a onclick="sortandpagingViewerAll_LoginInDay('<?=$page?>','lv.viewer_ip',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteviewip ?></a></td>
					<td align="center"><a onclick="sortandpagingViewerAll_LoginInDay('<?=$page?>','lv.version',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteviewerver?></a></td>
					<td align="center"><a onclick="sortandpagingViewerAll_LoginInDay('<?=$page?>','lv.status',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $status?></a></td>
					<td align="center"><a onclick="sortandpagingViewerAll_LoginInDay('<?=$page?>','lv.viewer_time',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteviewtime?></a></td>
					<td align="center"><a onclick="sortandpagingViewerAll_LoginInDay('<?=$page?>','lv.ins_time',1,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')" style="cursor: pointer;color: #027acc"><?php echo $inserttime?></a></td>
				</tr>
			</thead>
			<?php
			if(mysql_num_rows($selectlogviewer)>0){
				$i=0;
				while ($row = mysql_fetch_array($selectlogviewer)){
					if ( $i >= $page_start ){?>
					<tr>
						<td align="center" style="width:4%;background: white;color: #5D5D5D;font-weight: normal;"><?php echo $i+1?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[email] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[viewer_ip] ?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[version]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[status]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[viewer_time]?></td>
						<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[ins_time]?></td>
					</tr>
			<?php
					}
						$i++;
						if ($i >= $page_end){
							break;
						}
					}
				}
			?>
			
			<tr>
					<td colspan="8" class="rf-dt-shdr-c">
						<span style="padding:1px; display: inline-block;">
													
							<?php if ( $number_of_page > 1 ) 
							{ 
								if ($page==1)
									$p=2;
								else if ($page==$number_of_page)
									$p=$number_of_page-1;
								else $p=$page;
								if($page!=1){?>
									<a onclick="sortandpagingViewerAll_LoginInDay(<?=1?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')" ><span class='button_next'><?php echo "<<<";?></span> </a>
									<a onclick="sortandpagingViewerAll_LoginInDay(<?=($page-1)?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')"><span class='button_next'><?php echo "<<";?></span> </a>
								<?php  }
								else{
									echo "<span class='button_next'><<<</span> "; 
									echo "<span class='button_next'><<</span> ";
								}
								for ( $i = $p-1; $i <= $p+1; $i++ ) {	
										if ($i<=$number_of_page && $i>0)
										
											if ($i==$page){
												echo "<span class='button_next'><b>".$i."</b></span>"; 
											}else{
											?>
												<a onclick="sortandpagingViewerAll_LoginInDay(<?=$i?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')"><span class="button_next">
												<?php 
												echo $i;
												?>
												</span> </a>
												<?php 
											}
										?>
									
								<?php 
										}
									
									if($page!=$number_of_page){ ?>
										<a onclick="sortandpagingViewerAll_LoginInDay(<?=($page+1)?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')"><span class='button_next'><?php echo ">>";?></span> </a>
										<a onclick="sortandpagingViewerAll_LoginInDay(<?=$number_of_page?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['searchfrom']?>','<?=$_REQUEST['searchto']?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$emails?>')"><span class='button_next'><?php echo ">>>";?></span> </a>
									<?php }
									else{
										echo "<span class='button_next'>>></span> ";
										echo "<span class='button_next'>>>></span> ";
									}
								}
							
								
								?>
																					
						</span>
					</td>
				</tr>